﻿using System;

using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>
    /// Represents a choice between items that a <see cref="CommandGroupStyle"/> instance can contain.
    /// </summary>
    /// <remarks>A <see cref="CommandGroupStyle.Items"/> collection can contain commands
    /// (see <see cref="CommandStyle"/>) and sub-groups (see <see cref="CommandGroupStyle"/>).</remarks>
    public sealed class CommandGroupItem
    {
        #region FieldPermissions.

        object item;
        bool isGroup;
        bool isCommand;

        #endregion

        #region Constructors.

        /// <summary>
        /// Initializes a new instance of <b>CommandGroupItem</b> class.
        /// </summary>
        /// <param name="group">Group. Null is not allowed.</param>
        public CommandGroupItem(CommandGroupStyle group)
        {
            if (group == null)
                throw new ArgumentNullException("group", "Null is not allowed.");

            this.item = group;
            this.isGroup = true;
        }

        /// <summary>
        /// Initializes a new instance of <b>CommandGroupItem</b> class.
        /// </summary>
        /// <param name="command">Command. Null is not allowed.</param>
        public CommandGroupItem(CommandStyle command)
        {
            if (command == null)
                throw new ArgumentNullException("command", "Null is not allowed.");

            this.item = command;
            this.isCommand = true;
        }

        #endregion

        #region Properties.

        /// <summary>
        /// Gets an instance of <see cref="CommandGroupStyle"/> that this item represents.
        /// <b>null</b> reference if the item does not represent a group.
        /// </summary>
        public CommandGroupStyle Group
        {
            get { return (this.isGroup) ? (CommandGroupStyle)this.item : null; }
        }

        /// <summary>
        /// Gets an instance of <see cref="CommandStyle"/> that this item represents.
        /// <b>null</b> reference if the item does not represent a command.
        /// </summary>
        public CommandStyle Command
        {
            get { return (this.isCommand) ? (CommandStyle)this.item : null; }
        }

        #endregion
    }
}